package com.hy.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

public class ResultUtils {
    private static ObjectMapper objectMapper = new ObjectMapper();

    public static ResponseResult<?> result(ResponseResult<?> rr, HttpServletRequest request, HttpServletResponse response){
        if (rr !=null){
            try {
                String jsonStr = objectMapper.writeValueAsString(rr);
                PrintWriter out = response.getWriter();
                out.print(jsonStr);
                out.flush();
                out.close();
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }


        }

        return rr;
    }


}
